package com.shangdiao.sd_server.util;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * 获得spring加载的bean
 * @author btshen
 *
 */
public class SpringUtil {
	
	private static ApplicationContext context;
	
	static{
		context =  ApplicationHelper.getApplicationContext();
		if(context == null){
			context = new ClassPathXmlApplicationContext("spring/springContext.xml");
			System.out.println("手工初始化spring环境！springContext.xml");
		}
	}
    
	public static <T> T getBean(Class<T> clazz){
		return context.getBean(clazz);
	}
	
	public static Object getBean(String name){
		return context.getBean(name);
	}
	
	public static ApplicationContext getApplicationContext(){
		return context;
	}
	
	public static ApplicationContext getApplicationContext(String[] path){
		return new ClassPathXmlApplicationContext(path);
	}
	
}
